import 'package:flutter/material.dart';
import 'package:mine_sweeping/game_setting.dart';

class BlockContainer extends StatefulWidget {
  const BlockContainer(
      {Key? key,
      required this.blockType,
      required this.value,
      required this.onTap,
      required this.onDoubleTap})
      : super(key: key);
  final BlockType blockType;
  final int value;
  final VoidCallback onTap;
  final VoidCallback onDoubleTap;

  @override
  State<BlockContainer> createState() => _BlockContainerState();
}

class _BlockContainerState extends State<BlockContainer> {
  _buildChild() {
    Widget child = SizedBox.shrink();
    switch (widget.blockType) {
      case BlockType.figure:
        child = Center(
          child: Text("${widget.value}"),
        );
        break;
      case BlockType.mine:
        child = Icon(Icons.bolt);
        break;
      case BlockType.label:
        child = Icon(
          Icons.flag,
          color: Colors.red,
        );
        break;
      case BlockType.unlabeled:
        break;
    }
    return child;
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: widget.onTap,
      onDoubleTap: widget.onDoubleTap,
      child: ColoredBox(
        color: widget.blockType == BlockType.figure
            ? Color(0xff2F9997)
            : Color(0xff5BDFD1),
        child: _buildChild(),
      ),
    );
  }
}
